﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using WDS900.WebServer.Models;

namespace WDS900.WebServer.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class ManagerController : ControllerBase
    {
        private readonly ILogger<WeatherForecastController> _logger;
        private readonly IHubContext<NotificationHub> _hubContext;

        public ManagerController(ILogger<WeatherForecastController> logger, IHubContext<NotificationHub> hubContext)
        {
            _logger = logger;
            _hubContext = hubContext;

        }

        [HttpPost("recipeSelectRequest")]
        public async Task<IActionResult> recipeSelectRequest(RecipeSelectRequest request)
        {
            // 向特定客户端发送消息
            await _hubContext.Clients.Group(request.messageId)
                .SendAsync("ReceiveNotification", request.recipe.name);

            RecipeSelectResponse response = new(200)
            {
                messageId = request.messageId,
                replyCode = "00000000"
            };
            return response;
        }
    }
}
